$(function () {
    let shopName = location.search.split("=")[1];
    let dataID = location.hash.split("#")[1];
    localStorage.setItem('sy' + dataID, dataID);

    let str = "";
    let str1 = "";
    Object.keys(data).forEach(function (key) {
        data[key].filter(function (v) {
            if (v.goodsid == dataID) {
                str = `
                <div class="exzoom" id="exzoom">
                    <!--大图区域-->
                    <div class="exzoom_img_box">
                        <ul class='exzoom_img_ul'>
                        `;
                v.goodsurls.picsurl.forEach(function (v1, i) {
                    str += `<li><img src="${v1}"/></li>`
                });
                str += `
                        </ul>
                    </div>
                    <!--缩略图导航-->
                    <div class="exzoom_nav"></div>
                    <!--控制按钮-->
                    <p class="exzoom_btn">
                        <a href="javascript:void(0);" class="exzoom_prev_btn"> &lt; </a>
                        <a href="javascript:void(0);" class="exzoom_next_btn"> &gt; </a>
                    </p>
                </div>
        `;
                $('.K_G-left').append(str);
                str1 = `
    <div class="name">
                    ${v.goodstitle}
                </div>
                <!--价格之类的-->
                <div class="summary">
                    <!-- 价格信息-->
                    <div class="summary-price-wrap">
                        <div class="s-p-w-wrap">
                            <!-- 商城价 -->
                            <div class="summary-item si-shop-price">
                                <div class="si-tit">商城价</div>
    
                                <div class="si-warp">
                                    <strong class="shop-price"> ¥${v.goodszprice}</strong>
                                    <span class="price-notify">降价通知</span>
                                </div>
                            </div>
                            <!-- 会员价 -->
                            <div class="summary-item  si-shop-price" id="vip_register">
                                <div class="si-warp on_vip_register">
                                    <i class="icon icon-vip"></i>
                                    <span>高级VIP可享超值优惠价 </span>
                                    <span class="color-red" id="card_discount_price">¥97.20</span>
                                    <span class="onVipRegister">立即开通 &gt;&gt;</span>
                                </div>
                            </div>
                            <!-- 市场价 -->
                            <div class="summary-item si-market-price">
                                <div class="si-tit">市 场 价</div>
                                <div class="si-warp">
                                    <div class="m-price">
                                        ¥${v.goodsprice}
                                    </div>
                                </div>
                            </div>
                            <div class="si-info">
                                <div class="si-cumulative" style="border-right: 1px solid #d2d2d2;">累计评价
                                    <span class="fc-red">0</span>
                                </div>
                                <div class="si-cumulative">累计销量
                                    <span class="fc-red">${v.sales}</span>
                                </div>
                            </div>
                            <div class="si-phone-code">
                                <div class="qrcode-wrap">
                                    <div class="qrcode_tit">手机购买
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--地区信息 数量-->
                    <div class="summary-basic-info">
                        <div class="summary-item is-stock">
                            <div class="si-tit">配送</div>
                            <div class="si-warp">
                                <!--市-->
                                <span class="initial-area">北京市</span>
                                <span>至</span>
                                <div class="store-selector">
                                    <div class="text-select">
                                        <div class="tit">
                                            <span>河南省 郑州市 中原区 枫杨街道</span>
                                        </div>
                                    </div>
                                </div>
                                <div class="store-warehouse">
                                    <div class="store-prompt">
                                        <strong>有货</strong>，下单后立即发货
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="summary-item is-service">
                            <div class="si-tit">服务</div>
                            <div class="si-warp">
                                <div class="fl">
                                    <a href="javascript:void(0);" class="link-red">${v.shopname}</a> 发货并提供售后服务。
                                </div>
                                <div class="fl pl10">
                                    <span class="gary">[ 免运费 ]</span>
                                </div>
                            </div>
                        </div>
                        <!-- 可用积分-->
                        <div class="summary-item is-integral">
                            <div class="si-tit">可用积分</div>
                            <div class="si-warp">
                                <span class="integral">0</span>
                            </div>
                        </div>
                        <!-- 数量-->
                        <div class="summary-item is-number">
                            <div class="si-tit">数量</div>
                            <div class="si-warp">
                                <div class="amount-warp">
                                    <input type="text" class="text buy-num" name="" value="1">
                                    <div class="a-btn">
                                        <a href="javascript:void(0);" class="btn-add iconfont enableA">&and;</a>
                                        <a href="javascript:void(0);" class="btn-reduce btn-disabled iconfont">&or;</a>
                                    </div>
                                </div>
                                <!--库存-->
                                <span>
                                    库存
                                    <em id="goods_attr_num">${v.goodscount}</em> 个
                                </span>
                            </div>
                        </div>
                    </div>
                    <!--温馨提示-->
                    <div class="summary-basic-info">
                        <div class="summary-item is-service">
                            <div class="si-tit">温馨提示</div>
                            <a href="javascript:void(0);" class="label_url label_wrap ahover">
                                <img src="https://x.dscmall.cn/storage/data/goods/services_label/%E6%AD%A3%E7%A1%AE2.png"
                                    alt="" width="16"> 支持7天无理由退货
                            </a>
                        </div>
                    </div>
                </div>
                <!--按钮 购买-->
                <div class="choose-btns ml60 clearfix">
                    <a href="javascript:void(0);" class="btn-buynow">立即购买</a>
                    <a href="javascript:void(0);" class="btn-append">
                        加入购物车
                    </a>
                </div>
    `;
            }
        })
    });

    $('.K_G-content').append(str1);
    let str2 = '';
    for (let i = 0; i < 3; i++) {

        str2 += `
<li>
<a href="javascript:void(0)" id="${data[shopName][i].goodsid}" class="loca">
<img src="${data[shopName][i].goodsurls.nowurl}"
	width="140" height="140">
	</a>
<p class="p-name">
${data[shopName][i].goodstitle}
</p>
<p class="price">
${data[shopName][i].goodszprice}
</p>
</li>`
    }
    $('.K_GR-ul').html(str2);
    $(".loca").on("click", function () {
        location.href = "../html/goods.html?shopName=" + shopName + "#" + $(this).attr("id");
        location.reload();
    })
    move();

    function move() {
        $(".btn-append").mouseenter(function () {
            let img = $(this).parents(".K_goods").children(".K_G-left").find(".current img").attr("src");
            console.log(img);
            $(this).shoping({
                endElement: ".cxdiw", //结束元素节点，即页面上购物车位置
                iconCSS: "border:0", //飞过的图片样式
                iconImg: img, //飞过的图片信息
                endFunction: function (element) { //动画结束后的回调
                    return false;
                }
            });
        })
    }
});
